<?php

namespace app\admin\controller\datav;

use think\facade\Db;
use app\common\controller\Backend;
use app\common\controller\HaiKang;

class Index extends Backend
{
    protected $model = null;
    
    protected $noNeedLogin      = ['index'];//生成土壤墒情测试数据
    

    public function initialize()
    {
        parent::initialize();
    }

    /**
     * datav首页接口
     */
    public function index()
    {
        $param = $this->request->param();
        $monitorCount = Db::name('park_monitor')->count();//监控
        $ledscreeCount = Db::name('park_ledscree')->count();//显示屏
        $voiceCount = Db::name('park_voice')->count();//音柱
        $lampLigtCount = Db::name('park_lamp_ligt')->count();//照明
        $sosCount = Db::name('park_talk_sos')->count();//一键呼救

        $ledLog = Db::name('park_led_programs')->where('state',1)->order('uptime DESC')->find();//led屏幕最新播放
        $ledLog['pic_url'] = 'http://127.0.0.1:8088/images'.$ledLog['pic_url'];
        $ledLog['video_url'] = 'http://127.0.0.1:8088/images'.$ledLog['video_url'];
        $monitor =Db::name('park_monitor')->where('is_delete',0)->select();//摄像头
        $s = [];
        foreach ($monitor as $index=>$value) {
            $haiKangApi = new Haikang();
            $jianKong = $haiKangApi->get_previewURLs($value['uniq_code']);
            $jianKong = json_decode($jianKong,true);
            $s[$index]['name']=$value['name'];
            $s[$index]['path']=isset($jianKong['data']['url'] ) ? $jianKong['data']['url']  : '';
        }
        $backData = [
            'baseInfo'=>[
                'monitorCount'=>$monitorCount,
                'ledscreeCount'=>$ledscreeCount,
                'voiceCount'=>$voiceCount,
                'lampLigtCount'=>$lampLigtCount,
                'sosCount'=>$sosCount
            ],
            'ledInfo'=>[
                'ledLog'=>$ledLog
            ],
            'data'=>$s,
            'monitor'=>[
                'path'=>isset($jianKong['data']['url'] ) ? $jianKong['data']['url']  : ''
               
            ]
        ];
        $this->success('请求成功',$backData);
    }
    

}